<!DOCTYPE html>
<html>
<head>
    <meta charset="">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link rel="stylesheet" href="../assets/css/layui.css">
    <link rel="stylesheet" href="../assets/css/view.css"/>
    <title></title>
</head>
<body class="layui-view-body">
    <div class="layui-content">
        <div class="layui-row">
            <div class="layui-card">
                <div class="layui-card-header">添加部门</div>
                  <div class="layui-form-item">
                    <label class="layui-form-label">部门名称</label>
                    <div class="layui-input-block">
                      <input id="name" type="text" name="title" required  lay-verify="required" placeholder="部门名称" autocomplete="off" class="layui-input">
                    </div>
                  </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">部门介绍</label>
                        <div class="layui-input-block">
                            <input id="introduction" type="text" name="title" required  lay-verify="required" placeholder="部门介绍" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                  <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">组名</label>
                    <div class="layui-input-block">
                      <textarea id="group" name="desc" placeholder="输入组名，多个组名请用逗号分开" class="layui-textarea"></textarea>
                    </div>
                  </div>
                  <div class="layui-form-item">
                    <div class="layui-input-block">
                      <button id="submit" class="layui-btn layui-btn-blue" lay-submit lay-filter="formDemo">立即提交</button>
                      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                  </div>
            </div>
        </div>
    </div>
    <script src="../assets/layui.all.js"></script>
    <script>

        layui.use(['form','layer','jquery','upload','laydate'], function(){
            var form = layui.form,
                layer = layui.layer,
                $ = layui.jquery;

            var xhrOnProgress=function(fun) {
                xhrOnProgress.onprogress = fun; //绑定监听
                //使用闭包实现监听绑
                return function() {
                    //通过$.ajaxSettings.xhr();获得XMLHttpRequest对象
                    var xhr = $.ajaxSettings.xhr();
                    //判断监听函数是否为函数
                    if (typeof xhrOnProgress.onprogress !== 'function')
                        return xhr;
                    //如果有监听函数并且xhr对象支持绑定时就把监听函数绑定上去
                    if (xhrOnProgress.onprogress && xhr.upload) {
                        xhr.upload.onprogress = xhrOnProgress.onprogress;
                    }
                    return xhr;
                }
            }
            $("#submit").click(function () {
                $.ajax({
                    url: '../department.do',//待定
                    data: {
                        name:$("#name").val(),
                        introduction:$("#introduction").val(),
                        group:$("#group").val(),
                        tran:'add'
                    },
                    dataType: 'json',
                    type: 'post',
                    success: function(data) {
                        if (data.code == '0'){
                            layer.msg(data.msg)
                            $("#name").val("")
                            $("#introduction").val("")
                            $("#group").val("")
                        }else {
                            layer.msg("出现错误！");
                        }

                    },
                    error:function (jqXHR, textStatus, errorThrown) {

                    }
                })
                return false;
            })

        })

    </script>

</body>
</html>